__author__ = 'suphawking'
import asyncio
global id
import time
class go:
    def __init__(self,lock):
        self.lock=lock
    @asyncio.coroutine
    def do(self):
        yield from lock.acquire()
        for n in range(3):
            yield from asyncio.sleep(1)
        print(time.localtime(time.time()))
        lock.release()
@asyncio.coroutine
def my_coroutine(go):

    try:
        yield from go.do()
        print('ok')

    finally:
        pass



lock = asyncio.Lock()
go=go(lock)
loop = asyncio.get_event_loop()
tasks = [
    asyncio.async( my_coroutine(go)),
    asyncio.async( my_coroutine(go)),
    asyncio.async( my_coroutine(go))]

loop.run_until_complete(asyncio.wait(tasks))
#loop.run_until_complete(asyncio.gather(*tasks))
loop.close()